//
//  Category.swift
//  ToDoList
//
//  Created by Qingke on 16/4/14.
//  Copyright © 2016年 Qingke. All rights reserved.
//

import UIKit

class Category: NSObject,NSCoding{

    var name: String
    var iconName: String
    var tasks = [Task]()
    
    init(name: String) {
        self.name = name
        self.iconName = "Appointments"

    }
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(name, forKey: "name")
        aCoder.encodeObject(tasks, forKey: "tasks")
        aCoder.encodeObject(iconName, forKey: "iconName")
    }
   required init?(coder aDecoder: NSCoder) {
        self.name = aDecoder.decodeObjectForKey("name") as! String
        self.tasks = aDecoder.decodeObjectForKey("tasks") as! [Task]
    self.iconName = aDecoder.decodeObjectForKey("iconName") as! String
        super.init()
    }
    
    func openTaskCount() -> Int {
        var count = 0
        for task in tasks {
            if !task.IsChecked {
                count++
            }
        }
        return count
        
        
    }
}
